package com.wangzifan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangzifan.entity.Grade;
import com.wangzifan.entity.PageBean;
import com.wangzifan.entity.Student;
import com.wangzifan.mapper.GradeMapper;
import com.wangzifan.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {
    @Autowired
    private GradeMapper gradeMapper;

//    @Override
//    public Grade queryGradeByTno(String tno) {
//        return gradeMapper.queryGradeByTno(tno);
//    }

    @Override
    public void deleteGrade(List<Integer> ids) {
        gradeMapper.deleteGrade(ids);
    }

    @Override
    public void addGrade(Grade grade) {
        gradeMapper.addGrade(grade);
    }

    @Override
    public void updateGrade(Grade grade) {
        gradeMapper.updateGrade(grade);
    }

    @Override
    public Grade queryGradeById(Integer id) {
        return gradeMapper.queryGradeById(id);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String sno, String cno) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Grade> grades = gradeMapper.queryGrade(sno,cno);
        Page<Grade> p = (Page<Grade>) grades;

        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public PageBean pageByTeacher(Integer page, Integer pageSize, String tno, String cno) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Grade> grades = gradeMapper.queryGradeByTeacher(tno,cno);
        Page<Grade> p = (Page<Grade>) grades;

        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
